package com.wanghua.mall.order.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
 * @author wanghua
 * @create 2021-09-07 19:43
 */
@Component
@RabbitListener(queues = {"java.queue"})
public class RabbitTestListen {

    /**
     * 测试接受消息
     *
     * @param message org.springframework.amqp.core.Message
     * @param list    发送的消息类型
     * @param channel 传输数据的通道
     */
    @RabbitHandler
    public void receiveMessage(Message message, List<Integer> list, Channel channel) {
        System.out.println("List===>>>" + list);
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        System.out.println("deliveryTag1===>" + deliveryTag);
        try {
            channel.basicAck(deliveryTag, false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RabbitHandler
    public void receiveMessage(Message message, Set<Integer> set, Channel channel) {
        System.out.println("Set===>>>" + set);
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        System.out.println("deliveryTag2===>" + deliveryTag);
        try {
            channel.basicAck(deliveryTag, false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
